package com.hankol.winecellar.adapter

import android.content.Context
import android.os.Bundle
import android.widget.ImageView
import android.widget.LinearLayout
import com.baselibrary.Constants
import com.baselibrary.extension.checkNotNull
import com.baselibrary.extension.checkValue
import com.baselibrary.manager.SensorsDataManager
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.ARouterUtils
import com.baselibrary.utils.DoubleClickHelper
import com.baselibrary.utils.TimeUtil
import com.baselibrary.view.VipHeardImgView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.MultiTransformation
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.winecellar.R
import com.hankol.winecellar.bean.WineryEvaluateListBean
import com.hankol.winecellar.utils.BaseConstant
import com.baselibrary.view.PhotosContentView
import com.baselibrary.view.PhotosContentViewAdapter

/*酒窖全部评价列表
*
* */
class AllEvaluateAdapter :
        BaseQuickAdapter<WineryEvaluateListBean, BaseViewHolder>(R.layout.item_common_manage) {

    override fun convert(helper: BaseViewHolder, item: WineryEvaluateListBean) {
        //隐藏 编辑 删除按钮
        helper.setGone(R.id.img_edit, false)
        helper.setGone(R.id.v_line_v, false)
        helper.setGone(R.id.img_del, false)
        helper.setGone(R.id.v_bottom, helper.adapterPosition != data.size - 1)
        helper.setText(R.id.tv_name, item.name.checkValue())
                .setText(R.id.tv_time, TimeUtil.fromToday(item.ctime))
        val heardImg = helper.getView<VipHeardImgView>(R.id.civ_cover)
        item.let {
            heardImg.setData(it.icon, it.isFans == 1);
        }
        helper.setText(R.id.tv_content, item.wineryCommentDesc.checkValue())
        val nineGridPhoto = helper.getView<PhotosContentView<String>>(R.id.photo_content_view)
        nineGridPhoto.setAdapter(object : PhotosContentViewAdapter<String>() {
            override fun onDisplayImage(context: Context, imageView: ImageView, data: String) {
                Glide.with(context).load(data).placeholder(R.drawable.ic_def_hanxiang_228)
                        .error(R.drawable.ic_def_hanxiang_228).apply(
                                RequestOptions().transform(
                                        MultiTransformation(
                                                CenterCrop(),
                                                RoundedCorners(12)
                                        )
                                )
                        ).into(imageView)
            }

            override fun onItemImageClick(
                    context: Context,
                    imageView: ImageView,
                    index: Int,
                    list: MutableList<String>
            ) {
                super.onItemImageClick(context, imageView, index, list)
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    SensorsDataManager.instance.cellarCommentSee(item.wineryCommentDesc)
                    //图片详情
                    val bundle = Bundle()
                    bundle.putStringArrayList(Constants.KEY_URLS, list as ArrayList<String>)
                    bundle.putInt(Constants.KEY_INDEX, index)
                    bundle.putStringArrayList(
                            Constants.KEY_COMMENT_CONTENT,
                            arrayListOf(item.wineryCommentDesc)
                    )
                    bundle.putStringArrayList(Constants.KEY_COMMENT_TITLE, arrayListOf())
                    ActivityRouter.startActivity(
                            ActivityRouter.WINE_CELLAR.IMG_VIDEO_DETAIL,
                            bundle
                    )
                }
            }
        })
        if (item.wineryCommentImg.checkNotNull()) {
            nineGridPhoto.setImageData(item.wineryCommentImg.split(",").toMutableList())
        }
        helper.getView<VipHeardImgView>(R.id.civ_cover).setOnClickListener {
            if (!DoubleClickHelper.isOnDoubleClick()) {
                val hashMap = HashMap<String, Any>()
                hashMap[BaseConstant.USER_ID] = item.uid
                ARouterUtils.jump(ActivityRouter.MINE_CENTER.USER_INFO, hashMap)
            }
        }
        helper.getView<LinearLayout>(R.id.ll_name).setOnClickListener {
            if (!DoubleClickHelper.isOnDoubleClick()) {
                val hashMap = HashMap<String, Any>()
                hashMap[BaseConstant.USER_ID] = item.uid
                ARouterUtils.jump(ActivityRouter.MINE_CENTER.USER_INFO, hashMap)
            }
        }
    }
}